<template>
    <el-container id="container">
        <!-- 侧边栏 -->
         <el-aside width="250px">
            <el-container id="top">
                <div style="margin: auto;color: #fff;font-size: 22px;font-weight: bold;">
                    电商后台管理系统
                </div>
            </el-container>
            <!-- 功能菜单 -->
            <el-menu
                :default-active="$route.path"
                style="height: 100%;"
                background-color="#545c64"
                text-color="#fff"
                active-text-color="#ffd04b"
                @select="selectedItem"
            >
                <el-sub-menu index="1">
                    <template #title>
                        <el-icon><GoldMedal /></el-icon>
                        <span>营销与推广</span>
                    </template>
                    <el-menu-item index="/home/operational">运营位管理</el-menu-item>
                    <el-menu-item index="/home/operationalAdd">创建位管理</el-menu-item>
                </el-sub-menu>
                <el-sub-menu index="2">
                    <template #title>
                        <el-icon><ShoppingBag /></el-icon>
                        <span>商品管理</span>
                    </template>
                    <el-menu-item index="/home/category">类别管理</el-menu-item>
                    <el-menu-item index="/home/goodsManager">商品管理</el-menu-item>
                    <el-menu-item index="/home/goodsEdit">编辑商品</el-menu-item>
                </el-sub-menu>
            </el-menu>
         </el-aside>
         <!-- 主内容区 -->
          <el-main style="padding: 0;">
            <!-- 添加一个通用的头部 -->
             <el-header style="margin: 0;padding: 0;height: 80px;">
                <el-container 
                    style="background-color: blanchedalmond;
                    margin: 0;padding: 0;height: 80px;">
                    <div style="margin: auto;margin-left: 100px;">
                        <h1>欢迎您登录后台系统，
                            <span style="font-weight: bold;color: blueviolet;">
                                {{ account.$state.userInfo?.username }}
                            </span>
                            !
                        </h1>
                    </div>
                    <div style="margin: auto;margin-right: 50px;">
                        <el-button type="primary" @click="logout">注销</el-button>
                    </div>
                </el-container>
             </el-header>
             <!-- 这里用来渲染具体的功能模块组件 -->
              <router-view></router-view>
          </el-main>
    </el-container>
</template>
<script setup lang="ts">
import { useAccountStore } from '../base/AccountStore';
import { useRouter } from 'vue-router';
import { PageName } from '../base/Router';
import { GoldMedal } from '@element-plus/icons-vue';

const account = useAccountStore();
const router = useRouter();
// 选中某个菜单项的方法
const selectedItem = (item: string) => {
    // 跳转到对应的路由
    router.push({
        path: item
    });
}
// 退出登录的方法，将页面跳转到登录页
const logout = () => {
    account.logout();
    router.replace({
        name: PageName.login
    });
}
</script>
<style scoped>
    #container {
        height: 100%;
        width: 100%;
        position: absolute;
    }
    #top {
        background-color: #545c64;
        margin-right: 1px;
        text-align: center;
        height: 60px;
    }
</style>